package lp.xian.materials.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import lp.xian.materials.vo.PurchaseVo;
import lp.xian.materials.vo.WareVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import lp.xian.materials.domain.WarehousingRequisition;
import lp.xian.materials.service.IWarehousingRequisitionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 采购入库单Controller
 *
 * @author ruoyi
 * @date 2023-08-10
 */
@RestController
@RequestMapping("/warehousingRequisition/warehousingRequisition")
public class WarehousingRequisitionController extends BaseController
{
    @Autowired
    private IWarehousingRequisitionService warehousingRequisitionService;
    /**
     * 审批采购订单列表
     */
    @PreAuthorize("@ss.hasPermi('warehousingRequisition:warehousingRequisition:audit')")
    @Log(title = "审核", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult auditWare (@RequestBody WareVo wareVo)  {
        return toAjax(warehousingRequisitionService.auditWare(wareVo));
    }
    /**
     * 查询采购入库单列表
     */
    @PreAuthorize("@ss.hasPermi('warehousingRequisition:warehousingRequisition:list')")
    @GetMapping("/list")
    public TableDataInfo list(WarehousingRequisition warehousingRequisition)
    {
        startPage();
        List<WarehousingRequisition> list = warehousingRequisitionService.selectWarehousingRequisitionList(warehousingRequisition);
        return getDataTable(list);
    }

    /**
     * 导出采购入库单列表
     */
    @PreAuthorize("@ss.hasPermi('warehousingRequisition:warehousingRequisition:export')")
    @Log(title = "采购入库单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WarehousingRequisition warehousingRequisition)
    {
        List<WarehousingRequisition> list = warehousingRequisitionService.selectWarehousingRequisitionList(warehousingRequisition);
        ExcelUtil<WarehousingRequisition> util = new ExcelUtil<WarehousingRequisition>(WarehousingRequisition.class);
        util.exportExcel(response, list, "采购入库单数据");
    }

    /**
     * 获取采购入库单详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehousingRequisition:warehousingRequisition:query')")
    @GetMapping(value = "/{warehousingRequisitionId}")
    public AjaxResult getInfo(@PathVariable("warehousingRequisitionId") Integer warehousingRequisitionId)
    {
        return success(warehousingRequisitionService.selectWarehousingRequisitionByWarehousingRequisitionId(warehousingRequisitionId));
    }

    /**
     * 新增采购入库单
     */
    @PreAuthorize("@ss.hasPermi('warehousingRequisition:warehousingRequisition:add')")
    @Log(title = "采购入库单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WarehousingRequisition warehousingRequisition)
    {
        return toAjax(warehousingRequisitionService.insertWarehousingRequisition(warehousingRequisition));
    }

    /**
     * 修改采购入库单
     */
    @PreAuthorize("@ss.hasPermi('warehousingRequisition:warehousingRequisition:edit')")
    @Log(title = "采购入库单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WarehousingRequisition warehousingRequisition)
    {
        return toAjax(warehousingRequisitionService.updateWarehousingRequisition(warehousingRequisition));
    }

    /**
     * 删除采购入库单
     */
    @PreAuthorize("@ss.hasPermi('warehousingRequisition:warehousingRequisition:remove')")
    @Log(title = "采购入库单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{warehousingRequisitionIds}")
    public AjaxResult remove(@PathVariable Integer[] warehousingRequisitionIds)
    {
        return toAjax(warehousingRequisitionService.deleteWarehousingRequisitionByWarehousingRequisitionIds(warehousingRequisitionIds));
    }
}
